
package com.hlkj.pay.service.merchant.impl;
/*
 * Hlpay-Plus aggregate payment system.
 * Copyright (c) 2024-2025 Hlpay Team Copyright has the right of final interpretation.
 */

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import com.hlkj.framework.common.pojo.PageParam;
import com.hlkj.framework.common.pojo.PageResult;
import com.hlkj.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.hlkj.pay.dto.merchant.DefaultFeeConfigQueryDto;
import com.hlkj.pay.infrastructure.mapper.merchant.DefaultFeeConfigMapper;
import com.hlkj.pay.infrastructure.model.merchant.DefaultFeeConfigDO;
import com.hlkj.pay.service.CommonSnFilterService;
import com.hlkj.pay.service.merchant.IMerchantDefaultConfigService;

import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;

/**
 * @author HlpayTeam
 * @date 2024/11/01 17:20
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class MerchantDefaultConfigServiceImpl extends CommonSnFilterService implements IMerchantDefaultConfigService {

    private final DefaultFeeConfigMapper defaultFeeConfigMapper;

    @Override
    public PageResult<DefaultFeeConfigDO> queryPage(PageParam pageParam, DefaultFeeConfigQueryDto defaultFeeConfigQueryDto) {
        LambdaQueryWrapperX<DefaultFeeConfigDO> queryWrapper = new LambdaQueryWrapperX<>();
        filterSn(defaultFeeConfigQueryDto);
        queryWrapper.eqIfPresent(DefaultFeeConfigDO::getSn, defaultFeeConfigQueryDto.getSn());
        queryWrapper.inIfPresent(DefaultFeeConfigDO::getSn, defaultFeeConfigQueryDto.getSnList());
        queryWrapper.eqIfPresent(DefaultFeeConfigDO::getSnType, defaultFeeConfigQueryDto.getSnType());
        return defaultFeeConfigMapper.selectPage(pageParam,queryWrapper);
    }

    @Override
    public DefaultFeeConfigDO queryDetail(Long id) {
        return defaultFeeConfigMapper.selectById(id);
    }

    @Override
    public DefaultFeeConfigDO queryDetail(Integer snType, String sn) {
        LambdaQueryWrapperX<DefaultFeeConfigDO> queryWrapper = new LambdaQueryWrapperX<>();
        queryWrapper.eqIfPresent(DefaultFeeConfigDO::getSn, sn);
        queryWrapper.eqIfPresent(DefaultFeeConfigDO::getSnType, snType);
        return defaultFeeConfigMapper.selectOne(queryWrapper);
    }

    @Override
    public void addFeeConfig(DefaultFeeConfigDO defaultFeeConfigDO) {
        defaultFeeConfigMapper.insert(defaultFeeConfigDO);
    }

    @Override
    public void updateFeeConfig(DefaultFeeConfigDO defaultFeeConfigDO) {
        defaultFeeConfigMapper.updateById(defaultFeeConfigDO);
    }

    @Override
    public void delDefaultConfig(Long id) {
        defaultFeeConfigMapper.deleteById(id);
    }

    @Override
    public void updateAdStatus(Long id, Integer status) {
        DefaultFeeConfigDO defaultFeeConfigDO = new DefaultFeeConfigDO();
        defaultFeeConfigDO.setId(id);
        defaultFeeConfigDO.setStatus(status);
        defaultFeeConfigMapper.updateById(defaultFeeConfigDO);
    }
}
